<template>
	<div class="WechatBind">
		<v-header></v-header>
		<mt-field label="微信账号" placeholder="请输入微信账号" v-model="wechatNum"></mt-field>
		<div id="button-box" class="button-box">
			<mt-button type="default" size="large" @click.native="submitSure">确 认</mt-button>
		</div>
	</div>
</template>
<style>
	.WechatBind{margin-top: 4rem;}
	.mint-button--default {background-color: #cecece;}
	.button-box{padding: 10px;margin-top:20px;}
    .mint-button {font-size: 1.3rem;}
	
</style>
<script>
	import router from './../../router';
	import util from './../../js/util/util.js';
	import vHeader from './../common/Header.vue';
	import { Cell,Toast } from 'mint-ui';
	export default {
		data() {
			return {
				userData: {},
				wechatNum:''
			}
		},
		created() {
			this.$store.state.headings = this.$router.history.current.name; //修改标题
			this.$store.state.isFooterShow = false; //显示底部导航
		},
		components: {
			vHeader,
			Toast,
			Cell
		},
		methods: {
			submitSure: function() { //确认
				let wechatNum = this.wechatNum;
				if(!wechatNum || wechatNum.length == 0) {
					this.$toast('请输入微信账号！')
					return false;
				}
				util.Ajax('/userCentered/bindingWechat', "POST",{"wechat": wechatNum}, function(data) { //成功
					if(data) {
						if(data.code == "0") {
							Toast("保存成功");
							//不允许修改，隐藏按钮
							document.getElementById("button-box").style.display = "none";
						} else {
							Toast("保存失败");
						}
					}
				})
			}
		},
		mounted: function() { //加载完成后执行
			var $this = this;
			util.Ajax('/userCentered/getMemeberById', "POST", {}, function(data) { //成功
				if(data) {
					if(data.code == "0") {
						//赋值
						$this.userData = data.member;
						$this.wechatNum = data.member.wxUser;
						if(!util.isEmpty(data.member.wxUser)){
							document.getElementById("button-box").style.display = "none";
						}
					} else {
						Toast(data.msg);
					}
				}
			})
		}
	}
</script>
